package com.teamcenter.rac.massupdate.ui.grid.layers;

import ca.odell.glazedlists.EventList;
import com.teamcenter.rac.massupdate.ui.grid.ColumnAccessor;
import com.teamcenter.rac.massupdate.ui.grid.GridColumn;
import com.teamcenter.rac.massupdate.ui.grid.IGridRow;
import net.sourceforge.nattable.copy.command.CopyDataCommandHandler;
import net.sourceforge.nattable.data.IColumnPropertyAccessor;
import net.sourceforge.nattable.data.ListDataProvider;
import net.sourceforge.nattable.extension.glazedlists.GlazedListsEventLayer;
import net.sourceforge.nattable.layer.AbstractLayerTransform;
import net.sourceforge.nattable.layer.DataLayer;
import net.sourceforge.nattable.layer.cell.ColumnOverrideLabelAccumulator;
import net.sourceforge.nattable.reorder.ColumnReorderLayer;
import net.sourceforge.nattable.selection.SelectionLayer;
import net.sourceforge.nattable.viewport.ViewportLayer;
@SuppressWarnings({"rawtypes","unchecked"})
public class MassUpdateBodyLayerStack<T extends IGridRow> extends AbstractLayerTransform {
	private final SelectionLayer m_selectionLayer;
	private final ViewportLayer m_viewportLayer;
	private final ColumnReorderLayer m_columnReorderLayer;
	private final IColumnPropertyAccessor<T> m_columnAccessor;
	private final ListDataProvider<T> m_bodyDataProvider;
	private final DataLayer m_bodyDataLayer;
	private final GlazedListsEventLayer<T> m_glazedListsEventLayer;
	private final ColumnOverrideLabelAccumulator m_columnLabelAccumulator;

	public MassUpdateBodyLayerStack(GridColumn[] paramArrayOfGridColumn, EventList<T> paramEventList) {
		this.m_columnAccessor = new ColumnAccessor(paramArrayOfGridColumn);
		this.m_bodyDataProvider = new ListDataProvider(paramEventList, this.m_columnAccessor);
		this.m_bodyDataLayer = new DataLayer(this.m_bodyDataProvider);
		this.m_glazedListsEventLayer = new GlazedListsEventLayer(this.m_bodyDataLayer, paramEventList);
		this.m_columnReorderLayer = new ColumnReorderLayer(this.m_glazedListsEventLayer);
		this.m_selectionLayer = new SelectionLayer(this.m_columnReorderLayer);
		this.m_viewportLayer = new ViewportLayer(this.m_selectionLayer);
		setUnderlyingLayer(this.m_viewportLayer);
		this.m_columnLabelAccumulator = new ColumnOverrideLabelAccumulator(this.m_bodyDataLayer);
		this.m_bodyDataLayer.setConfigLabelAccumulator(this.m_columnLabelAccumulator);
		registerCommandHandler(new CopyDataCommandHandler(this.m_selectionLayer));
	}

	public ColumnReorderLayer getColumnReorderLayer() {
		return this.m_columnReorderLayer;
	}

	public SelectionLayer getSelectionLayer() {
		return this.m_selectionLayer;
	}

	public ViewportLayer getViewportLayer() {
		return this.m_viewportLayer;
	}

	public IColumnPropertyAccessor<T> getColumnAccessor() {
		return this.m_columnAccessor;
	}

	public ListDataProvider<T> getDataProvider() {
		return this.m_bodyDataProvider;
	}

	public DataLayer getDataLayer() {
		return this.m_bodyDataLayer;
	}

	public GlazedListsEventLayer<T> getGlazedListsEventLayer() {
		return this.m_glazedListsEventLayer;
	}

	public ColumnOverrideLabelAccumulator getColumnLabelAccumulator() {
		return this.m_columnLabelAccumulator;
	}
}
